package com.example.mapper;

import com.example.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("INSERT INTO user (user_id, username, email) VALUES (#{userId}, #{username}, #{email})")
    void insert(User user);

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    @Results({
            @Result(property = "userId", column = "user_id"),  // 映射 user_id 到 userId
            @Result(property = "username", column = "username"),
            @Result(property = "email", column = "email")
    })
    User selectById(Long userId);

    @Select("SELECT * FROM user")
    @Results({
            @Result(property = "userId", column = "user_id"),  // 映射 user_id 到 userId
            @Result(property = "username", column = "username"),
            @Result(property = "email", column = "email")
    })
    List<User> selectAll();

    @Select("SELECT count(user_id) FROM user")
    Integer count();
}